package com.atguigu.cloud.controller;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.atguigu.cloud.entities.Merchant;
import com.atguigu.cloud.entities.Order;
import com.atguigu.cloud.sevice.Impl.OrderServiceImpl;
import com.atguigu.cloud.tool.load.page.PaginationResult;
import com.atguigu.cloud.tool.resp.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.basic.BasicDesktopIconUI;
import java.util.List;

/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.controller
 * @className: ordercontrollor
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 18:28
 * @version: 1.0
 */
@Tag(name = "订单表", description = "订单表增删改")
@RestController
public class Ordercontrollor {
    @Resource
    OrderServiceImpl orderService;


    //增加订单
    @PostMapping(value = "/order/add")
    @Operation(summary = "添加订单", description = "添加订单,这里的日期穿字符串就行20个字符")
    public ResultData<String> addorder(@RequestBody Order order){
        System.out.println(order.toString());
        int i = orderService.add(order);
        return ResultData.success("成功插入记录，返回值："+i);
    }

    //删除订单
    @DeleteMapping(value = "/order/del/{id}")
    @Operation(summary = "删除订单", description = "删除订单")
    public ResultData<Integer> deleteorder(@PathVariable("id") Integer id) {
        Integer i=orderService.delete(id);
        return ResultData.success(i);
    }

    //修改订单
    @PutMapping(value = "/order/update")
    @Operation(summary = "修改订单", description = "修改订单")
    public ResultData<String> updateorder(@RequestBody Order order){
        int i = orderService.update(order);
        return ResultData.success("成功修改记录，返回值："+i);
    }

    //根据proid查询订单
    @GetMapping(value = "/order/get/{orderid}")
    @Operation(summary = "根据订单查询订单", description = "查询订单")
    public ResultData<Order> getById(@PathVariable("orderid") Integer id) {
        Order order = orderService.getById(id);
        return ResultData.success(order);
    }
    //根据userid查询订单
    @GetMapping(value = "/order/getbyuserid/{userid}")
    @Operation(summary = "根据用户id查询订单", description = "查询订单")
    public ResultData<List<Order>> getByUserId(@PathVariable("userid") Integer id) {
        return ResultData.success(orderService.getByUserid(id));
    }

    //查询所有订单
    @GetMapping(value = "/order/getall")
    @Operation(summary = "查询所有订单", description = "查询所有订单")
    public ResultData<List<Order>> getAll() {
        return ResultData.success(orderService.getAll());
    }

    //分页查询所有订单
    @GetMapping(value = "/order/paginationQuery/getall/{currentPage}")
    @Operation(summary = "分页的进行订单的查询", description = "分页的进行订单的查询")
    public ResultData<PaginationResult<Order>> paginationQuery(@PathVariable("currentPage") Integer currentPage){
        return ResultData.success(orderService.myPaginationQuery(currentPage));
    }

    //根据userid进行订单的分页查询
    @GetMapping(value = "/order/paginationQuery/getbyuserid/{userid}/{currentPage}")
    @Operation(summary = "根据用户id分页查询订单", description = "根据用户id分页查询订单")
    public ResultData<PaginationResult<Order>> paginationQueryByUserid(@PathVariable("userid") Integer userid,@PathVariable("currentPage") Integer currentPage){
        return ResultData.success(orderService.paginationQueryByUserid(userid,currentPage));
    }


}
